<?php
namespace app\index\controller;

use think\Db;

class Index extends Base
{
    public function index()
    {
        // echo json_encode($this->categories);
        for ($i=0; $i <count($this->categories) ; $i++) {
            switch ($this->categories[$i]->id) {
                case 1:
                    # 材料数据
                    $data_clsj = $this->categories[$i];
                    break;
                case 6:
                    # 腐蚀数据
                    $data_fssj = $this->categories[$i];
                    break;
                case 9:
                    # 环境数据
                    $data_hjsj = $this->categories[$i];
                    break;
                case 14:
                    # 电化学数据
                    $data_dhxsj = $this->categories[$i];
                    break;
                case 15:
                    # 图谱数据
                    $data_tpsj = $this->categories[$i];
                    break;
                case 18:
                    # 测试资源
                    $data_cszy = $this->categories[$i];
                    break;
                case 21:
                    # 信息资源
                    $data_xxzy = $this->categories[$i];
                    break;
                default:
                    break;
            }
        }
        // 图谱数据
        foreach ($data_tpsj->child as $key => $value) {
            foreach ($value->child as $val) {
                // var_dump($val->tablename);
                $tablename = $val->tablename;
                $data = Db::table($tablename)->field('id, title, metallograph_file')->order('id', 'desc')->find();
                $metallograph_file=explode(",", $data['metallograph_file']);
                list($thumb,$pic)=explode("::::::", $metallograph_file[0]);
                $data['title_pic'] = $pic;
                // var_dump($data);
                $val->home_data = $data;
            }
        }
        // echo json_encode($data_tpsj);
        // exit;
        $this->assign('data_clsj',$data_clsj);
        $this->assign('data_fssj',$data_fssj);
        $this->assign('data_hjsj',$data_hjsj);
        $this->assign('data_tpsj',$data_tpsj);
        $this->assign('data_dhxsj',$data_dhxsj);
        $this->assign('data_cszy',$data_cszy);
        $this->assign('data_xxzy',$data_xxzy);
        return $this->fetch();
    }
}
